<h1>
<?php 
	echo CActiveRecord::model('Product')->findByPk($model->product)->ut_product_name;
?>
</h1>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'calc-form',
//	'enableAjaxValidation'=>true,
)); ?>

	<p class="note">Обязательные к заполнению <span class="required">*</span>поля</p>
	
	<?php echo $form->errorSummary($model); ?>
	
	<div class="row">
<?php 
		echo $form->labelEx($model,'colority');
		echo CHtml::activeDropDownList($model,'colority',CActiveRecord::model('Colority')->base(array('base'=>(!$model->baseColority)?1:0))->listData('ut_colority_id','colorityName'));
		echo $form->error($model,'colority');			
?>		
		<div class="group">
<?php		
		echo $form->labelEx($model,'baseColority');
		echo CHtml::activeCheckBox($model,'baseColority',array(
				'ajax'=>array(
					'success'=>'js: function(html){jQuery("#'.CHtml::activeId($model,'colority').'").replaceWith($(html).find("#'.CHtml::activeId($model,'colority').'"));}',
					'type'=>'POST',
			 	),
			 'return'=>true,
			 'uncheckValue'=>null,
			//'onclick'=>'js: alert("qwe");',
			)
		);			  
?>
		</div>
	</div>

	<div class="row">
	<?php echo $form->labelEx($model,'format'); ?>		
		<div class="group">
<?php				
		echo CHtml::activeDropDownList($model,'format',CHtml::listData(CActiveRecord::model('Format')->findAll(),'ut_format_id','ut_format_name'),
			array(
				'onchange'=>'jQuery("#'.CHtml::activeId($model,'formatWidth').'").val("");jQuery("#'.CHtml::activeId($model,'formatHeight').'").val("");',
				'ajax'=>array(
					'type'=>'POST',
					'success'=> 'js:function(html){
							jQuery("#'.CHtml::activeId($model,'formatWidth').'").replaceWith($(html).find("#'.CHtml::activeId($model,'formatWidth').'"));
							jQuery("#'.CHtml::activeId($model,'formatHeight').'").replaceWith($(html).find("#'.CHtml::activeId($model,'formatHeight').'"));}',
				),
				'return'=>true
			));
		echo $form->error($model,'format');
		echo CHtml::activeLabel($model,'formatWidth');
		echo CHtml::activeTextField($model,'formatWidth');
		echo $form->error($model,'formatWidth');
		echo CHtml::activeLabel($model,'formatHeight');
		echo CHtml::activeTextField($model,'formatHeight'); 
		echo $form->error($model,'formatHeight');
?>
		</div>
	</div>


	<div class="row">
<?php 
		echo $form->labelEx($model,'paperKind');
		echo CHtml::activeDropDownList($model,'paperKind',CActiveRecord::model('PaperKind')->listData(),
			array(
				'ajax'=>array(
					'type'=>'POST',
					'success'=> 'js:function(html){
							jQuery("#'.CHtml::activeId($model,'density').'").replaceWith($(html).find("#'.CHtml::activeId($model,'density').'"));}',
				),
				'return'=>true,
		));
		echo $form->error($model,'paperKind');
?>
	</div>

	<div class="row">
<?php 
		echo $form->labelEx($model,'density'); 
		echo CHtml::activeDropDownList($model,'density',CActiveRecord::model('Density')->paperKind(array('paperKind'=>$model->paperKind))->listData('ut_density_id','ut_density_value'));
		echo $form->error($model,'density'); 
?>
	</div>

	<div class="row">
<?php 
		echo $form->labelEx($model,'edition'); 
		echo CHtml::activeTextField($model,'edition');
		echo $form->error($model,'edition'); 
?>
	</div>

	<div class="row submit">
		<?php echo CHtml::submitButton('Calculate'); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->

<?php 
	if (!Yii::app()->request->isAjaxRequest && $model->validate()){ 
		$this->widget('zii.widgets.grid.CGridView', array(
		'dataProvider'=>$model->calculate(isset($_POST['CalcForm'])),
		'enablePagination'=>false,
		'summaryText'=>false,
	//	'template'=>'',
		//'filter'=>$model,
		'columns'=>array(
			array(
				'class'=>'CLinkColumn',
				'header'=>'Печатная машина',
				'labelExpression'=>'$data[ut_press_name]',
				'urlExpression'=>'array("calcpress","press"=>$data[ut_press_id])',
			//	'label'=>'Печатная машина',
			),
			array(
				'name'=>'calcDensity',
				'header'=>'Тираж машины',
				'value'=>'number_format($data->calcDensity,2,"."," ");',
				'htmlOptions'=>array('class'=>'align-right'),
			),			
			array(
				'name'=>'calcSum',
				'header'=>'Сумма',
				'value'=>'number_format($data->calcSum,2,"."," ");',
				'htmlOptions'=>array('class'=>'align-right'),
			),						
		),
	));
} 
?>
